function delay(duration) {
    var start = new Date()
    while (Date.now() - start < duration) {}
}

setTimeout(() => {
    console.log(1)
}, 0);

Promise.resolve().then(()=>{
    console.log(3)
})

delay(5000)

console.log(2)